#ifndef GSMIO_H_

#ifdef __cplusplus
extern "C" {
#endif
//#include <targets/lpc2000.h>

#include "ff.h"
#include "rtea.h"
#include "json.h"

#include "modem.h"


#define GSMIO_PULLUPS_OFF()   {PINMODE4 = (PINMODE4 & ~0x0000FFFF) | 0x0000AAAA;}


#define GSMIO_POWER_ON()      {FIO2DIR |= 0x00000008; FIO2CLR =  0x00000008;}
#define GSMIO_POWER_OFF()     {FIO2DIR |= 0x00000008; FIO2SET =  0x00000008;}

#define GSMIO_SET_KEY()       {FIO2DIR |= 0x00000040; FIO2SET =  0x00000040;}
#define GSMIO_CLR_KEY()       {FIO2DIR |= 0x00000040; FIO2CLR =  0x00000040;}

#define GSMIO_SIM(n)          ((n==GSM_SIM1)?(GSMIO_SIM1()):(GSMIO_SIM2()))

//#define GSMIO_SIM1()          {FIO2DIR |= 0x00000200; FIO2SET =  0x00000200;}
#define GSMIO_SIM2()          {FIO2DIR |= 0x00000200; FIO2CLR =  0x00000200;}

#define GSMTASK_CONN_ATTEMPTS 1
#define GSMTASK_SHUTDWN_ATTEMPTS 2
typedef enum
{
  GSM_CMD_OK = 0,
  GSM_CMD_TIMEOUT,
  GSM_CMD_ERROR
} GSM_CMD_t;


  
GSM_CMD_t gsmio_command(char* cmd, char* resp, int timeout_ms);
GSM_CMD_t gsmio_command_n(char* cmd, int len, char* resp, int timeout_ms, char flush);

void gsmio_power_on();
void gsmio_power_off();

void gsmio_on();

GSM_CMD_t gsmio_json_receive(unsigned long timeout_ms, json_node** output);
GSM_CMD_t gsmio_http_receive(FIL* file, unsigned int *crc32, unsigned long timeout_ms);


bool gsmtask_connect();

#ifdef __cplusplus
}
#endif


#endif /*GSMIO_H_*/